package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.CustomerService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;
    @Override
    public Map<String, Object> list(Integer page, Integer rows, String customerName) {
        //开启分页组件
        PageHelper.startPage(page,rows);
        Map<String,Object> map = new HashMap<>();
        Page<Customer> page1 = customerDao.list(page,rows,customerName);
        map.put("total",page1.getTotal());
        map.put("rows",page1.getResult());
        return map;
    }

    @Override
    public void add(Customer customer) {
        if (customer.getCustomerId()==null){
            customerDao.add(customer);
        }else{
            customerDao.updateById(customer);
        }

    }

    @Override
    public void delete(String ids) {
        String[] split = ids.split(",");
        customerDao.delete(split);
    }
}
